package cn.biwysh.exam.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.biwysh.exam.biz.ZhiShiBiz;
import cn.biwysh.exam.entity.User;

public class Zdyzsk extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		String url="WEB-INF/jsp/zdyzsk.jsp";
		HttpSession session = request.getSession(false);
		User user=null;
		ZhiShiBiz biz=new ZhiShiBiz();
		String ids=request.getParameter("ids");
		if(session!=null){
			if (session.getAttribute("userqt") != null) {
				user = (User) session.getAttribute("userqt");
				if(user!=null){
					if(ids!=null){
						String[] array=ids.split("#");
						int[] idlist;
						if(array.length==0){
							idlist=new int[0];
						}else {
							idlist=new int[array.length-1];
							int count=0;
							for(int i=0;i<array.length;i++){
								try
								{
									idlist[count]=Integer.parseInt(array[i]);
									count++;
								} catch (Exception e)
								{
								}
							}
						}
						biz.addSelfCategory(user.getId(), idlist);
						request.setAttribute("ok", "ok");
					}
					request.setAttribute("userlist", biz.GetSelfCate(user.getId()));
					request.setAttribute("list", biz.GetCategory());
					RequestDispatcher requestDispatcher = request.getRequestDispatcher(url);
					requestDispatcher.forward(request, response);
				}else{
					response.sendRedirect("index.do");
				}
			}else{
				response.sendRedirect("index.do");
			}
		}else{
			response.sendRedirect("index.do");
		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
     this.doGet(request, response);
	}

}
